﻿using ShopManagement.Model.EF;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ShopManagement
{
    public partial class UserEdit : Form
    {
        private readonly UserService services = new UserService();
        private readonly int userId;
        public UserEdit(int userId)
        {
            this.userId = userId;
            InitializeComponent();
        }
        
        public void LoadUserInfo(string userName, string userEmail,string userPassword,string userNumber)
        {
            textBox1.Text = userName;
            textBox2.Text = userNumber;
            textBox3.Text = userPassword;
            textBox4.Text = userEmail;
        }
        private void UserEdit_Load(object sender, EventArgs e)
        {

        }

        private void butOk_Click(object sender, EventArgs e)
        {
            // 获取用户输入的信息
            string userName = textBox1.Text;
            string userNumber= textBox2.Text;
            string userPassword= textBox3.Text;
            string userEmail = textBox4.Text;

            // 创建用户实体
            Users user = new Users
            {
                UserID = userId,
                UserName = userName,
                UserEmail = userEmail,
                UserPassword = userPassword,
                UserNumber = userNumber
            };

            // 更新数据库中的用户信息
            services.UpdateUser(user);

            this.DialogResult = DialogResult.OK;
            this.Close();

        }

        private void butCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
